#include "exynos_4412.h"

void Init_ADC(void){
	/*选择ADC的精确度 10/12bit */
	ADCCON = ADCCON | (1 << 16);
	/*选择ADC是否开启分频使能*/
	ADCCON = ADCCON | (1 << 14);
	/*选择ADC分频的值 
	 * ADC时钟频率 100MHz / (19+1) = 5MHz
	 * ADC转换频率 5MHZ / 5 = 1MHz*/
	ADCCON = ADCCON & (~(0xFF << 6)) | (19 << 6);
	/*选择ADC　正常模式 or STAND BY*/
	ADCCON = ADCCON & (~(1 << 2));
	/*关闭读触发使能*/
	ADCCON = ADCCON & (~(1 << 1));
	/*选择ADC 4个通道中　一个通道*/
	ADCCON = ADCCON & (~(0xF)) | (3);
}


int main()
{
	unsigned int Adc_Data;
	Init_ADC();
	//开启ADC开关
	ADCCON = ADCCON | 1;
	//判断AD转换器是否转换完成
	while(!(ADCCON & (1 << 15)));
	//读取转换结果
	Adc_Data = ADCDAT & 0xFF;
	//将结果转换为实际值　mV
	Adc_Data = Adc_Data * 0.44;
	//打印转换结果
	printf("Adc_Data = %dmV\n", Adc_Data);
	return 0;
}
